package com.control
{
	import com.view.awardItem;
	
	import flash.events.MouseEvent;
	import flash.events.Event;
	import sekati.display.Canvas;
	import sekati.display.CoreSprite;
	import br.com.stimuli.loading.BulkLoader;
	import br.com.stimuli.loading.BulkProgressEvent;
	/**
	 * The class is to manage the list of award item.
	 * */
	public class awardItemManager extends CoreSprite
	{
		private var bulkInstance:BulkLoader = new BulkLoader("AwardItem");	
		public var awardItemList:Array=new Array();
		public var awardItemListlength:Number=1;
		
		/**
	 	* constutor 
	 	* */
		public function awardItemManager()
		{
			super();
			initAwardItem();
			loaditem();
		}
		/**
	 	* this function is for loading item function 
	 	* */
		public function loaditem():void{								
			
			bulkInstance.add("./images/award/mvp.jpg");			
			bulkInstance.addEventListener(BulkLoader.COMPLETE, onAllLoaded);
			bulkInstance.addEventListener(BulkLoader.PROGRESS, onAllProgress);
			bulkInstance.addEventListener(BulkLoader.ERROR, onErrorOccur);
			bulkInstance.start();
		}
		
		/**
	 	* generate AwardItem and put into stage 
	 	* */
		public function initAwardItem():void{
			for (var i:int=0;i<awardItemListlength;i++){
				var awarditem:awardItem=new awardItem();				
				awardItemList.push(awarditem);
				addChild(awarditem);
				var xx:int=(i%3)*330+10-340;
				var yy:int=(Math.floor(i/3))*260+20
				awarditem.x=xx;
				awarditem.y=yy;
			}		
			x=Canvas.stage.stageWidth/2;
			y=300;
		}
		
		/**
	 	* stage resize handle function 
	 	* */
		public function resize():void{
			x=Canvas.stage.stageWidth/2;
			y=300;
		}
		private function onAllLoaded(evt : Event):void{
			awardItemList[0].setAwardPic(bulkInstance.getBitmap("./images/award/mvp.jpg"));
		}
		private function onAllProgress(evt : BulkProgressEvent):void{
			//trace(evt.percentLoaded);			
		}
		private function onErrorOccur(evt:Event):void{
			trace("onload image error");
			
		}
	}
}